package com.huike.web.controller.system;

import com.huike.clues.domain.SysDictData;
import com.huike.clues.domain.dto.SysDictDataAddDTO;
import com.huike.clues.domain.dto.SysDictDataQueryDTO;
import com.huike.clues.domain.result.PageResult;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {
    @Autowired
   private ISysDictDataService sysDictDataService;
    @GetMapping("/type/{dictType}")
    public AjaxResult<List<SysDictData>> saveType(@PathVariable String dictType) {
        List<SysDictData> list = sysDictDataService.saveType(dictType);
        return AjaxResult.success(list);
    }
    @GetMapping("/list")
    public TableDataInfo<SysDictData> list(SysDictDataQueryDTO dto){
        startPage();
       List<SysDictData> list = sysDictDataService.selectList(dto);
        return getDataTable(list);
    }
    @PostMapping
    public AjaxResult save(@RequestBody SysDictDataAddDTO dto){
        sysDictDataService.insert(dto);
        return AjaxResult.success();
    }
    @GetMapping("/{dictCode}")
    public AjaxResult selectByDictCode(@PathVariable Integer dictCode){
      SysDictData sysDictData = sysDictDataService.selectByDictCode(dictCode);
        return AjaxResult.success(sysDictData);
    }
    @PutMapping
    public AjaxResult update(@RequestBody SysDictData sysDictData){
        sysDictDataService.updateData(sysDictData);
        return AjaxResult.success();
    }
    @DeleteMapping("/{dictCodes}")
    public AjaxResult delete(@PathVariable String[] dictCodes){
        sysDictDataService.deleteByDictCodes(dictCodes);
        return AjaxResult.success();
    }
}
